﻿<UserControl x:Class="TeamProjectManager.Modules.WorkItemConfiguration.WorkItemTypesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:w="clr-namespace:TeamProjectManager.Modules.WorkItemConfiguration"
             xmlns:i="clr-namespace:TeamProjectManager.Common.Infrastructure;assembly=TeamProjectManager.Common"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <DataTemplate DataType="{x:Type w:WorkItemTypeDefinition}">
            <TextBlock Text="{Binding Path=Name}" />
        </DataTemplate>
    </UserControl.Resources>
    <TabControl>

        <TabItem Header="View / Export / Delete / Edit" i:HelpProvider.HelpContent="Allows you to get an overview of the work item type definitions across multiple Team Projects, how many work items have been created from them, and in which work item categories they are used. You can also export their definitions to XML files, edit them in-place, and delete the work item types from the Team Projects.">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Button Grid.Row="0" Content="Get Work Item Types" Margin="0,5,0,5" Command="{Binding Path=GetWorkItemTypesCommand}" />
                <DataGrid Grid.Row="1" ItemsSource="{Binding Path=WorkItemTypes}" IsReadOnly="True" AutoGenerateColumns="False" VerticalScrollBarVisibility="Auto" x:Name="workItemTypesDataGrid" SelectionChanged="workItemTypesDataGrid_SelectionChanged">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Team Project" Binding="{Binding Path=TeamProject.Name}" />
                        <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" />
                        <DataGridTextColumn Header="Number Of Work Items" Binding="{Binding Path=WorkItemCount}" />
                        <DataGridTextColumn Header="Used In Categories" Binding="{Binding Path=WorkItemCategoriesList}" />
                        <DataGridTextColumn Header="Description" Binding="{Binding Path=Description}" />
                    </DataGrid.Columns>
                </DataGrid>
                <WrapPanel Grid.Row="2" Margin="0,5,0,0">
                    <Button Content="Export" Command="{Binding Path=ExportSelectedWorkItemTypesCommand}" />
                    <Button Content="Delete" Margin="5,0,0,0" Command="{Binding Path=DeleteSelectedWorkItemTypesCommand}" />
                    <Button Content="Edit..." Margin="5,0,0,0" Command="{Binding Path=EditSelectedWorkItemTypesCommand}" />
                    <Button Content="Transform..." Margin="5,0,0,0" Command="{Binding Path=TransformSelectedWorkItemTypesCommand}" />
                </WrapPanel>
            </Grid>
        </TabItem>

        <TabItem Header="Import" i:HelpProvider.HelpContent="Allows you to validate and import new work item type definitions in existing Team Projects. This can be useful if you want to change the work item types being used, e.g. to upgrade them from a previous version.">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid Grid.Row="0" Margin="0,5,0,5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <ListBox Grid.Column="0" ItemsSource="{Binding Path=WorkItemTypeFiles}" SelectedItem="{Binding Path=SelectedWorkItemTypeFile}" SelectionMode="Single" Margin="5,0,0,0" />

                    <StackPanel Grid.Column="1" Orientation="Vertical" Margin="5,0,0,0">
                        <TextBlock><Hyperlink Command="{Binding Path=AddWorkItemTypeFileCommand}" ToolTip="Add a Work Item Type">add</Hyperlink></TextBlock>
                        <TextBlock><Hyperlink Command="{Binding Path=RemoveSelectedWorkItemTypeFileCommand}" ToolTip="Remove the selected Work Item Type">remove</Hyperlink></TextBlock>
                        <TextBlock><Hyperlink Command="{Binding Path=RemoveAllWorkItemTypeFilesCommand}" ToolTip="Remove all Work Item Types">remove all</Hyperlink></TextBlock>
                    </StackPanel>
                </Grid>

                <WrapPanel Grid.Row="1">
                    <Button Content="Import" Command="{Binding Path=ImportCommand}" Margin="5,0,0,0" />
                    <TextBlock VerticalAlignment="Center" Margin="5,0,0,0"><Hyperlink x:Name="macroInformationHyperlink" Command="{x:Static w:MacroInformationDialog.ShowInstanceCommand}">About macros</Hyperlink></TextBlock>
                    <CheckBox Content="Simulate only" ToolTip="Does not save any changes but simulates the process" IsChecked="{Binding Path=Simulate}" VerticalAlignment="Center" Margin="5,0,0,0" />
                    <CheckBox Content="Save a copy" ToolTip="Saves a copy of the imported files to the %TEMP% folder" IsChecked="{Binding Path=SaveCopy}" VerticalAlignment="Center" Margin="5,0,0,0" />
                </WrapPanel>

            </Grid>
        </TabItem>

        <TabItem Header="Search" i:HelpProvider.HelpContent="Allows you to search for work item types and/or fields within them. This can be useful if you want to know if certain work items or fields are present in selected Team Projects.">

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <Grid Grid.Row="0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.Column="0" Content="Search For" Margin="0,0,5,0" />
                    <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=SearchText, UpdateSourceTrigger=PropertyChanged}" />

                    <WrapPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="5,5,0,0">
                        <CheckBox IsChecked="{Binding Path=SearchIncludesWorkItemFields}" Content="Include work item fields" ToolTip="Enable this to also search within work item fields" Margin="0,0,10,0" />
                        <CheckBox IsChecked="{Binding Path=SearchUsesExactMatch}" Content="Match exactly" ToolTip="Enable this to limit search results to those that are equal to the search text (as opposed to containing the search text)" />
                    </WrapPanel>

                    <Button Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Content="Search" Command="{Binding Path=SearchCommand}" Margin="0,5,0,0" />
                </Grid>

                <DataGrid Grid.Row="1" ItemsSource="{Binding Path=SearchResults}" Margin="0,5,0,0" AutoGenerateColumns="False" IsReadOnly="True">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Team Project" Binding="{Binding Path=TeamProject}" />
                        <DataGridTextColumn Header="Type" Binding="{Binding Path=Type}" />
                        <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" />
                        <DataGridTextColumn Header="Reason" Binding="{Binding Path=Reason}" />
                    </DataGrid.Columns>
                </DataGrid>

            </Grid>

        </TabItem>

    </TabControl>
</UserControl>
